<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2020/1/16
 * Time: 19:35
 */
namespace app\api\controller;

use app\api\model\MtUser;
use app\api\model\MtUserStratum;
use app\util\ReturnCode;

/**
 * 分销
 * Class Distribution
 * @package app\api\controller
 */
class Distribution extends Base
{
    /**
     * 绑定分销上级
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function bindSuper(){
        $userID = intval($this->request->get("userID"));
        $inviteCode = $this->request->get("inviteCode");
        if(!$userID || !$inviteCode){
            return $this->error(ReturnCode::EMPTY_PARAMS,"缺少参数");
        }
        $superPeople = (new MtUser())->where([["inviteCode","=",$inviteCode],["status","=","1"]])->find();
        if(!$superPeople){
            return $this->error(ReturnCode::DB_READ_ERROR,"邀请码查询错误");
        }
        $insertRes = (new MtUserStratum())->insert(["userID"=>$userID,"pID"=>$superPeople],true);
        if(!$insertRes){
            return $this->error(ReturnCode::DB_SAVE_ERROR,"绑定失败");
        }
        return $this->success("绑定成功");
    }

    /**
     * 获取分销二维码
     *
     */
    public function getDistributionQRcode(){
        $userID = intval($this->request->get("userID"));
        if(!$userID){
            return $this->error(ReturnCode::EMPTY_PARAMS,"缺少参数userID");
        }
        
    }


}